package com.yonyou.findata.kafka.policy;

import org.apache.kafka.common.errors.PolicyViolationException;
import org.apache.kafka.server.policy.CreateTopicPolicy;

import java.util.Map;

/**
 *
 * create.topic.policy.class.name=com.yonyou.findata.kafka.policy.PolicyDemo
 *
 * @author pizhihui
 * @date 2020-06-17
 */
public class PolicyDemo implements CreateTopicPolicy {


    @Override
    public void validate(RequestMetadata requestMetadata) throws PolicyViolationException {
        if (requestMetadata.numPartitions() < 3) {
            throw new PolicyViolationException("Topic should have at least 5 partitions , received: " + requestMetadata.numPartitions());
        }
    }

    @Override
    public void close() throws Exception {

    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
